<template>
  <div class="app-container">
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
      :default-sort="{prop: 'id', order: 'descending'}"
    >

      <el-table-column align="center" label="name" prop="name"></el-table-column>
      <el-table-column align="center" label="brand" prop="carList[0].brand"></el-table-column>
      <el-table-column align="center" label="color" prop="carList[0].color"></el-table-column>
      <el-table-column align="center" label="createTime" prop="carList[0].createTime"></el-table-column>


      <el-table-column
        fixed="right"
        label="操作"
        width="100">
        <!--        <template slot-scope="scope">
                  <el-button type="text" @click="update(scope.row)" size="small">修改用户详情</el-button>
                  <el-button @click="del(scope.row.id)" type="text" size="small">删除</el-button>
                </template>-->
      </el-table-column>
    </el-table>
    <div style="margin-top: 10px;text-align: center;align-items: center">
      <el-pagination
        background
        layout="prev, pager, next"
        :page-count="pages"
        v-model:current-page="currpage"
        @current-change="loadData"/>
    </div>
  </div>
</template>

<script>
import request from '@/utils/request'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      currpage: 1,
      list: [],


      listLoading: false,
      pages: 1,
      userdetial: '',

    }
  },
  mounted() {
    this.loadData()
  },
  methods: {
    loadData() {
      console.log(this.currpage);
      //请求接口 实现数据的查询
      this.listLoading = true
      request({
        url: "http://127.0.0.1:8080/api/user/carbelong/seldetialByUid.do?size=1&page=1&uid=" + this.$route.query.msg
      }).then(res => {

        this.list = res.data.list;
        this.pages = res.data.pages;
        this.listLoading = false;
      })
    },

    del(id) {
      this.$confirm('亲，是否确认删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        //请求接口 实现数据的删除
        request({
          url: "http://127.0.0.1:8080/api/user/userdetial/del.do?id=" + id
        }).then(res => {
          if (res.code == 0) {
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
            this.loadData();
          }
        })

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    update(obj) {
      //设置Vuex的数据
      this.$store.commit("user/setUserDetial", obj);
      //跳转页面 路由
      this.$router.push("/userdetialupdate");
    }
  }
}
</script>
